package org.lansir.af.reminder;

import org.lansir.af.R;

import android.content.Context;
import android.media.MediaPlayer;

/**
 * @author 蓝智宏
 * 
 */
public class AlarmSound {
	// fields
	private Context context = null;
	private MediaPlayer mMediaPlayer = null;

	// methods
	public AlarmSound(Context context) {

		this.context = context;
		mMediaPlayer = MediaPlayer.create(context, R.raw.afalarm);
	}

	public void play() {
		if (mMediaPlayer == null) {
			mMediaPlayer = MediaPlayer.create(context, R.raw.afalarm);
		}
		mMediaPlayer.start();

	}

	public void playWithLoop() {
		if (mMediaPlayer == null) {
			mMediaPlayer = MediaPlayer.create(context, R.raw.afalarm);
		}
		mMediaPlayer.setLooping(true);
		mMediaPlayer.start();
	}

	public boolean isPlaying() {
		if (mMediaPlayer == null)
			return false;
		return mMediaPlayer.isPlaying();
	}

	@Override
	public void finalize() {
		mMediaPlayer.release();
		mMediaPlayer = null;
	}

	public void stop() {
		mMediaPlayer.stop();
	}

}
